package com.yehun.config;

import java.sql.*;
import java.text.SimpleDateFormat;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;

/**
 * mybatis日期时间类型处理
 */

@MappedTypes({ String.class })
@MappedJdbcTypes({ JdbcType.TIMESTAMP, JdbcType.DATE })
public class DateTypeHandler implements TypeHandler<Object> {

    public String getResult(ResultSet rs, String columnName) throws SQLException {
        Timestamp timestamp = rs.getTimestamp(columnName);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        return dateFormat.format(timestamp);
    }

    public String getResult(ResultSet rs, int columnIndex) throws SQLException {
        return null;
    }

    public String getResult(CallableStatement cs, int columnIndex) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    public void setParameter(PreparedStatement arg0, int arg1, Object arg2, JdbcType arg3) throws SQLException {
        // TODO Auto-generated method stub
    }


}